//package com.carhailing.client.service.impl;
//
//import com.carhailing.client.config.ShardingStrategyConstant;
//import com.carhailing.client.mapper.OrderPartitionByIdMapper;
//import com.carhailing.client.mapper.OrderPartitionByUserIdMapper;
//import com.carhailing.common.domain.response.CarOrder;
//import org.junit.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.util.concurrent.ThreadLocalRandom;
//
//
//public class ShardingTest {
//    @Autowired
//    OrderPartitionByIdMapper orderPartitionByIdMapper;
//
//    @Autowired
//    OrderPartitionByUserIdMapper orderPartitionByUserIdDao;
//
//    @Test
//    public void testCreateOrderRandom() {
//        for (int i = 0; i < 20; i++) {
//            int userId = ThreadLocalRandom.current().nextInt(1000,1000000);
//            CarOrder CarOrder = new CarOrder;
//
//            CarOrder.getStartCarId(SeqIdUtil.nextId(userId % ShardingStrategyConstant.SHARDING_TABLE_NUM));
//            CarOrder.setOrderNumber((long) userId);
//            CarOrder.setOrderStatus(0);
//            CarOrder.setUserId((long) userId);
//
////            int ret = OrderPartitionByIdMapper.insertOrder(CarOrder);
////            Assert.assertEquals(1, ret);
//        }
//    }
//
////    @Test
////    public void testOrderAll() {
////        //insert
////        int userId = ThreadLocalRandom.current().nextInt(1000,1000000);
////        OrderEntity orderEntity = new OrderEntity();
////        orderEntity.setOrderId(SeqIdUtil.nextId(userId % ShardingStrategyConstant.SHARDING_TABLE_NUM));
////        orderEntity.setStatus(1);
////        orderEntity.setUserId(userId);
////        orderEntity.setCreateTime(new Date());
////        orderEntity.setUpdateTime(new Date());
////        orderEntity.setBookingDate(new Date());
////        int i = orderPartitionByIdDao.insertOrder(orderEntity);
////        Assert.assertEquals(1, i);
////
////        //get from master
////        OrderEntity orderInfo = orderPartitionByIdDao.getOrderByIdFromMaster(orderEntity.getOrderId());
////        Assert.assertNotNull(orderInfo);
////        Assert.assertEquals(orderInfo.getOrderId(), orderEntity.getOrderId());
////
////        //get from slave
////        OrderEntity slaveOrderInfo = orderPartitionByIdDao.getOrderById(orderEntity.getOrderId());
////        Assert.assertNotNull(slaveOrderInfo);
////        //update
////        OrderEntity updateEntity = new OrderEntity();
////        updateEntity.setOrderId(orderInfo.getOrderId());
////        updateEntity.setStatus(2);
////        updateEntity.setUpdateTime(new Date());
////        int affectRows = orderPartitionByIdDao.updateOrderByOrderId(updateEntity);
////        Assert.assertTrue( affectRows > 0);
////    }
////
////    @Test
////    public void testGetListByUserId() {
////        int userId = ThreadLocalRandom.current().nextInt(1000,1000000);
////        for (int i = 0; i < 5; i++) {
////            OrderEntity orderEntity = new OrderEntity();
////            orderEntity.setOrderId(SeqIdUtil.nextId(userId % ShardingStrategyConstant.SHARDING_TABLE_NUM));
////            orderEntity.setStatus(1);
////            orderEntity.setUserId(userId);
////            orderEntity.setCreateTime(new Date());
////            orderEntity.setUpdateTime(new Date());
////            orderEntity.setBookingDate(new Date());
////            orderPartitionByIdDao.insertOrder(orderEntity);
////        }
////        try {
////            //防止主从延迟引起的校验错误
////            Thread.sleep(1000);
////        } catch (InterruptedException e) {
////            e.printStackTrace();
////        }
////        List<OrderEntity> orderListByUserId = orderPartitionByUserIdDao.getOrderListByUserId(userId);
////        Assert.assertNotNull(orderListByUserId);
////        Assert.assertTrue(orderListByUserId.size() == 5);
////    }
//}
//
//
